package cn.mst.vrs.dal.mysql.auth;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.mst.vrs.controller.admin.auth.vo.AuthPageReqVO;
import cn.mst.vrs.dal.dataobject.auth.AuthDO;
import com.baomidou.mybatisplus.extension.toolkit.ChainWrappers;
import org.apache.ibatis.annotations.Mapper;

/**
 * 认证 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface VrsAuthMapper extends BaseMapperX<AuthDO> {

    default PageResult<AuthDO> selectPage(AuthPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AuthDO>()
                .eqIfPresent(AuthDO::getUserId, reqVO.getUserId())
                .eqIfPresent(AuthDO::getTypeId, reqVO.getTypeId())
                .eqIfPresent(AuthDO::getIdentifier, reqVO.getIdentifier())
                .eqIfPresent(AuthDO::getCredential, reqVO.getCredential())
                .betweenIfPresent(AuthDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AuthDO::getId));
    }

    default AuthDO selectOneBy(String identifier, Long authTypeId){
        return ChainWrappers.lambdaQueryChain(this)
                .eq(AuthDO::getIdentifier, identifier)
                .eq(AuthDO::getTypeId, authTypeId)
                .one();
    }
}